package cn.stylefeng.guns.modular.system.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import cn.stylefeng.guns.modular.system.model.BusinessCompany;
import cn.stylefeng.guns.modular.system.service.IBusinessCompanyService;

/**
 * 商家信息控制器
 *
 * @author fengshuonan
 * @Date 2019-10-23 18:32:21
 */
@Controller
@RequestMapping("/businessCompany")
public class BusinessCompanyController extends BaseController {

    private String PREFIX = "/system/businessCompany/";

    @Autowired
    private IBusinessCompanyService businessCompanyService;

    /**
     * 跳转到商家信息首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "businessCompany.html";
    }

    /**
     * 跳转到添加商家信息
     */
    @RequestMapping("/businessCompany_add")
    public String businessCompanyAdd() {
        return PREFIX + "businessCompany_add.html";
    }

    /**
     * 跳转到修改商家信息
     */
    @RequestMapping("/businessCompany_update/{businessCompanyId}")
    public String businessCompanyUpdate(@PathVariable Integer businessCompanyId, Model model) {
        BusinessCompany businessCompany = businessCompanyService.selectById(businessCompanyId);
        model.addAttribute("item",businessCompany);
        LogObjectHolder.me().set(businessCompany);
        return PREFIX + "businessCompany_edit.html";
    }

    /**
     * 获取商家信息列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return businessCompanyService.selectList(null);
    }

    /**
     * 新增商家信息
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(BusinessCompany businessCompany) {
        businessCompanyService.insert(businessCompany);
        return SUCCESS_TIP;
    }

    /**
     * 删除商家信息
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer businessCompanyId) {
        businessCompanyService.deleteById(businessCompanyId);
        return SUCCESS_TIP;
    }

    /**
     * 修改商家信息
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(BusinessCompany businessCompany) {
        businessCompanyService.updateById(businessCompany);
        return SUCCESS_TIP;
    }

    /**
     * 商家信息详情
     */
    @RequestMapping(value = "/detail/{businessCompanyId}")
    @ResponseBody
    public Object detail(@PathVariable("businessCompanyId") Integer businessCompanyId) {
        return businessCompanyService.selectById(businessCompanyId);
    }
}
